<template>
  <div>
    <el-card style="width:35rem;margin:10rem auto;">
      <div slot="header">
        <span>管理员登录</span>
      </div>
      <el-form @submit.native.prevent="login">
        <el-form-item label="用户名">
          <el-input type="text" v-model="user.username"></el-input>
        </el-form-item>
        <el-form-item label="用户密码">
          <el-input type="password" v-model="user.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" native-type="submit">提交</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  data () {
    return {
      user: {}
    }
  },
  methods: {
    async login () {
      const res = await this.$http.post('/login', this.user)
      console.log(res.data)
      localStorage.token = res.data || ''
      this.$message({ type: 'success', message: '登录成功' })
      this.$router.push('/')
    }
  }
}
</script>

<style scoped></style>
